import { createI18n } from 'vue-i18n'

import zh from './lang/zh-cn'
import en from './lang/en'
import pl from './lang/pl-pl'

const messages = {
    zh, en, pl
}
// i18n实例配置
/* export function getLanguage() {
    const chooselang = localStorage.getItem('locale')
    if (chooselang) return chooselang

    // if not shoose language
    const lang = (navigator.language || navigator.browserLanguage).toLowerCase()
    const locales = Object.keys(messages)
    return locales.includes(lang) ? lang : 'zh'
}

const i18n = createI18n({
    locale: getLanguage(),
    fallbackLocale: 'en',
    global: true,
    messages
})

export function $t(args) {
    return i18n.global.tc(args)
}

console.log($t('templates'))
export default app => {
    app.use(i18n)
} */
// 创建 i18n
const i18n = createI18n({
    legacy: false,
    globalInjection: true, // 全局模式，可以直接使用 $t
    locale: localStorage.getItem('lang') || 'zh',
    messages
})

export default i18n
